#pragma once
#include <vector>

using namespace std;

struct IMAGE_DATA_DIRECTORY_INFO {
    PVOID pVirtualAddress;
    PVOID pFileOffsetAddress;
    DWORD dwVirtualSize;
};

class PE
{
public:
    PE();
    ~PE();
    
    
    BOOL                            LoadFile();
    void                            UnLoadFile();
    BOOL                            InitPeFile();
    
    PIMAGE_NT_HEADERS               GetNtHeaders();
    PIMAGE_FILE_HEADER              GetFileHeader();
    PIMAGE_OPTIONAL_HEADER          GetOptionalHeader();
    PIMAGE_SECTION_HEADER           GetSectionHeader();
    PIMAGE_DATA_DIRECTORY           GetDataDirectory();
    PIMAGE_IMPORT_DESCRIPTOR        GetImportDescriptor();
    PIMAGE_EXPORT_DIRECTORY         GetExportDescriptor();
    
    DWORD                           RVAtoFOA(IN DWORD dwRVA, IN OPTIONAL DWORD dwImageBase = 0);
    DWORD                           FOAtoRVA(DWORD dwFOA);
    
    void                            GetTargetPlatform(CString &strMachine);
    void                            GetTargetCharacteristics(CString &strCharacter);
    void                            InitDataDirectoryTable();
    void                            InitSectionTable();
    
    vector<IMAGE_DATA_DIRECTORY>    GetDataDirectoryTable();
    vector<IMAGE_SECTION_HEADER>    GetSectionTable();
    
public:
    CString                             m_strFilePath;
    HANDLE                              m_hFile;
    HANDLE                              m_hMap;
    PVOID                               m_pImageBase;
    PIMAGE_DOS_HEADER                   m_pDosHeader;
    PIMAGE_NT_HEADERS                   m_pNtHeader;
    PIMAGE_FILE_HEADER                  m_pFileHeader;
    PIMAGE_OPTIONAL_HEADER              m_pOptionalHeader;    
    PIMAGE_DATA_DIRECTORY               m_pDataDirectory;
    PIMAGE_SECTION_HEADER               m_pSectionHeader;
    PIMAGE_IMPORT_DESCRIPTOR            m_pImportDescriptor;
    PIMAGE_EXPORT_DIRECTORY             m_pExportDirectory;

    vector<IMAGE_DATA_DIRECTORY>        m_vecDataDirectoryTable;
    vector<IMAGE_SECTION_HEADER>        m_vecSectionTable;

};

